<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
session_start();
class PaymentController extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->helper('url');	
	}
	
	function addPayment($student_number)
	{
		if(!isset($_SESSION["session_id"])) $this->load->view('ErrorNotLoggedInView');
		else{
		$_POST['student_number']=$student_number;
		$this->load->model('Payment_model');
		if($this->Payment_model->check_payment($_POST)){
			show_error('A Payment with that or number already exists!');
		}else{
			$this->Payment_model->add_payment($_POST);
			redirect('residentController/loadSearchResidentView/'.$student_number);
		}}
	}
	
	function loadViewPaymentView($student_number,$or_number,$type)
	{
		if(!isset($_SESSION["session_id"])) $this->load->view('ErrorNotLoggedInView');
		else{
		$_POST['student_number']=$student_number;
		$_POST['or_number']=$or_number;
		$_POST['type']=$type;
		$this->load->model('Payment_model');
		$data['info'] = $this->Payment_model->get_payment($_POST);
		$data['title'] = 'View Payment';
		$data['jsSnippet'] = 'jsSnippets/viewPaymentJsSnippet';
		$data['htmlSnippet'] = 'htmlSnippets/viewPaymentHtmlSnippet';
		$this->load->view('generic/GenericView',$data);}
	}
	
	function loadEditPaymentView($student_number,$or_number,$type)
	{
		if(!isset($_SESSION["session_id"])) $this->load->view('ErrorNotLoggedInView');
		else{
		$_POST['student_number']=$student_number;
		$_POST['or_number']=$or_number;
		$_POST['type']=$type;
		$this->load->model('Payment_model');
		$data['info'] = $this->Payment_model->get_payment($_POST);
		$data['title'] = 'Edit Payment';
		$data['jsSnippet'] = 'jsSnippets/editPaymentJsSnippet';
		$data['htmlSnippet'] = 'htmlSnippets/editPaymentHtmlSnippet';
		$this->load->view('generic/GenericView',$data);}
	}
	
	function editPayment()
	{
		if(!isset($_SESSION["session_id"])) $this->load->view('ErrorNotLoggedInView');
		else{
		$this->load->model('Payment_model');
		$this->Payment_model->edit_payment($_POST);
		redirect('residentController/loadSearchResidentView/'.$_POST['student_number']);}
	}
	
	function deletePayment($type)
	{
		if(!isset($_SESSION["session_id"])) $this->load->view('ErrorNotLoggedInView');
		else{
		$_POST['type_hidden']=$type;
		$this->load->model('Payment_model');
		$this->Payment_model->delete_payment($_POST);
		redirect('residentController/loadSearchResidentView/'.$_POST['student_number']);}
	}
	
}

/* End of file paymentController.php */
/* Location: ./application/controllers/paymentController.php */
?>